"use client"; import { getShopInfoApi, getShopListApi, ShopInfo } from "@/api/depositsApi"; import Loading from "@/components/Loading"; import React from "react"; import DepositData from "./DepositData"; import Left from "./Left"; const Deposit = () => { const [actIdx, setActIdx] = React.useState(0); const [shopTypeList, setShopTypeList] = React.useState([]); const [currentChannel, setCurrentChannel] = React.useState({}); const [shopInfo, setShopInfo] = React.useState({} as ShopInfo); const [loading, setLoading] = React.useState(false); const actChange = (idx: number) => { setActIdx(idx); doChangeChannel(shopTypeList[idx].pay_channel[0]); //TODO: dele }; const currentShop = React.useMemo(() => { return shopTypeList[actIdx]; }, [actIdx, shopTypeList]); React.useEffect(() => { getData(); }, []); React.useEffect(() => { const id = shopTypeList[actIdx]?.id; getInfo(id); }, [actIdx, shopTypeList]); const getData = async () => { const res = await getShopListApi(); if (res?.code === 200 && res?.data) { setShopTypeList(res?.data || []); if (res?.data[actIdx]?.pay_channel[0]) { doChangeChannel(res?.data[actIdx]?.pay_channel[0]); } } }; const getInfo = async (id: number) => { if (!id) { setShopInfo({} as ShopInfo); return; } try { setLoading(true); const res = await getShopInfoApi({ shop_id: id }); if (res?.code === 200 && res?.data?.products?.length) { res.data.products.sort((a: any, b: any) => { return a.pay - b.pay; }); //TODO: sort sho setShopInfo(res.data); } } finally { setLoading(false); } }; const doChangeChannel = (data: any) => { setCurrentChannel(data); }; console.log(9991, currentChannel); return (
{!loading && ( )} {loading && (
)}
); }; export default Deposit;